/* 对象的拷贝 */
let obj = {a: 1, b: {c: 1}}
let obj2 = {...obj}

obj.a = 2
console.log(obj2)  //{a:1,b:{c:1}}

obj.b.c = 2
console.log(obj2)  //{a:1,b:{c:2}}


/* 数组的拷贝 */
let arr = [1, 2, 3];
let newArr = [...arr]; //跟arr.slice()是一样的效果
let newArr2 = arr.slice();
console.log(newArr);
console.log(newArr2);

arr = [1, 2, {val: 4}];
newArr = arr.slice();
newArr[2].val = 1000;
console.log(arr);  //[ 1, 2, { val: 1000 } ]
